﻿//
// Copyright (c) 2011 Canyala Innovation AB
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 
// associated documentation files (the "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
// copies of the Software, and to permit persons to whom the Software is furnished to do so, 
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH 
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
//

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Canyala.Lagoon.Extensions;
using Canyala.Lagoon.Functional;

namespace Canyala.Lagoon.Tests
{
    [TestClass]
    public class SequenceExtensionsTest
    {
        [TestMethod] 
        public void Given_a_sequence_of_1_items_When_splitting_it_into_parts_of_1_Then_count_of_parts_should_be_1()
            { Assert.AreEqual(1, Seq.OfInts(1).Split(1).Count()); }

        [TestMethod] 
        public void Given_a_sequence_of_1_items_When_splitting_it_into_parts_of_2_Then_count_of_parts_should_be_1()
            { Assert.AreEqual(1, Seq.OfInts(1).Split(2).Count()); }

        [TestMethod] 
        public void Given_a_sequence_of_2_items_When_splitting_it_into_parts_of_1_Then_count_of_parts_should_be_2()
            { Assert.AreEqual(2, Seq.OfInts(2).Split(1).Count()); }

        [TestMethod] 
        public void Given_a_sequence_of_2_items_When_splitting_it_into_parts_of_2_Then_count_of_parts_should_be_1()
            { Assert.AreEqual(1, Seq.OfInts(2).Split(2).Count()); }

        [TestMethod] 
        public void Given_sequence_of_10_items_When_splitting_it_into_parts_of_5_Then_count_of_parts_should_be_2()
            { Assert.AreEqual(2, Seq.OfInts(10).Split(5).Count()); }

        [TestMethod] 
        public void Given_a_sequence_of_10_items_When_splitting_it_into_parts_of_2_Then_count_of_parts_should_be_5()
            { Assert.AreEqual(5, Seq.OfInts(10).Split(2).Count()); }

        [TestMethod] 
        public void Given_a_sequence_of_10_items_When_splitting_it_into_parts_of_4_Then_count_of_parts_should_be_3()
            { Assert.AreEqual(3, Seq.OfInts(10).Split(4).Count()); }

        [TestMethod] 
        public void Given_a_sequence_of_7_items_When_splitting_it_into_parts_of_3_Then_2_parts_should_have_count_of_3()
            { Assert.AreEqual(2, Seq.OfInts(7).Split(3).Where(partition => partition.Count() == 3).Count()); }

        [TestMethod] 
        public void Given_a_sequence_of_7_items_When_splitting_it_into_parts_of_3_Then_1_part_should_have_count_of_1()
            { Assert.AreEqual(1, Seq.OfInts(7).Split(3).Where(partition => partition.Count() == 1).Count()); }

        [TestMethod]
        public void Given_generator_upto_When_start_is_1_and_end_is_10_Then_resulting_sequence_should_have_count_of_10()
            { Assert.AreEqual(10, 1.UpTo(10).Count()); }

        [TestMethod]
        public void Given_generator_upto_When_start_is_1_and_end_is_10_Then_first_value_is_1()
            { Assert.AreEqual(1, 1.UpTo(10).First()); }

        [TestMethod]
        public void Given_generator_upto_When_start_is_1_and_end_is_10_Then_last_value_is_10()
            { Assert.AreEqual(10, 1.UpTo(10).Last()); }
    }
}
